package com.gxa.saas.admin.service.impl;

import com.gxa.saas.admin.entiry.GBGoodsVO;
import com.gxa.saas.admin.entiry.Menu;
import com.gxa.saas.admin.entiry.SGVO;
import com.gxa.saas.admin.mapper.GBGoodsMapper;
import com.gxa.saas.admin.service.GBGoodsService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Log4j2
public class GBGoodsServiceImpl implements GBGoodsService {


    @Autowired
    private GBGoodsMapper gbGoodsMapper=null;

    @Override
    public List<Menu> queryMenu() {
        List<Menu> menus = gbGoodsMapper.queryMenu();
        return menus;
    }

    @Override
    public List<GBGoodsVO> queryGoods() {
        return gbGoodsMapper.queryGoods();
    }

    @Override
    public List<GBGoodsVO> queryGoodsByCondition(SGVO sgvo) {
        if(sgvo.getName()=="") sgvo.setName(null);
        if(sgvo.getFirstMenu()=="") sgvo.setFirstMenu(null);
        if(sgvo.getSecondMenu()=="") sgvo.setSecondMenu(null);
//        log.info("================="+sgvo);
        return gbGoodsMapper.queryGoodsByCondition(sgvo);
    }

    @Override
    public Boolean goodsDown(Integer id) {
        if (gbGoodsMapper.querGStatus(id)==2) return gbGoodsMapper.goodsDown(id)>0;
        else return false;
    }

    @Override
    public Boolean goodsDelete(Integer id) {
        if(gbGoodsMapper.queryStatus(id)==0) return gbGoodsMapper.goodsDelete(id)>0;
        else return false;
    }

    @Override
    public List<GBGoodsVO> auditGoods() {
        return gbGoodsMapper.auditGoods();
    }

    @Override
    public List<GBGoodsVO> auditGoodsByCon(SGVO sgvo) {
        if(sgvo.getName()=="") sgvo.setName(null);
        if(sgvo.getFirstMenu()=="") sgvo.setFirstMenu(null);
        if(sgvo.getSecondMenu()=="") sgvo.setSecondMenu(null);
        return gbGoodsMapper.auditGoodsByCon(sgvo);
    }

    @Override
    public Integer updateGoods(Integer id, Integer Status) {
        if (gbGoodsMapper.querGStatus(id)==1) return gbGoodsMapper.updateGoods(id, Status);
        else return 0;
    }

}
